package com.war.controller.stock;

import com.war.dao.stock.DamagesDao;
import com.war.dao.warehousing.PurchaseDao;
import com.war.pojo.stock.DamagesInfo;
import com.war.pojo.warehousing.PurchaseInfo;
import com.war.service.safeManage.UserService;
import com.war.service.stock.DamagesInfoService;
import com.war.service.system.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/damages")
public class DamagesController {

    @Autowired(required = false)
    DamagesInfoService damagesInfoService;

    @RequestMapping("")
    public String list(DamagesInfo damagesInfo, ModelMap m){
        HashMap<String,Object> map = damagesInfoService.index(damagesInfo);
        //把数据传到前端
        m.put("info",map);
        return "stock/damages/damages-list";
    }

    //仓库
    @RequestMapping("/add")
    public String add(){
        return "stock/damages/damages-add";
    }

    @RequestMapping("/addAjax")
    @ResponseBody
    public HashMap<String,Object> addAjax(DamagesInfo damagesInfo){
        HashMap<String,Object> map = damagesInfoService.add(damagesInfo);
        return map;
    }

    @RequestMapping("/edit")
    public String edit(DamagesInfo damagesInfo,ModelMap m){
        HashMap<String,Object> map = damagesInfoService.selectById(damagesInfo);
        //把数据传到前端
        m.put("info",map);
        return "stock/damages/damages-edit";
    }

    @RequestMapping("/editAjax")
    @ResponseBody
    public HashMap<String,Object> editAjax(DamagesInfo damagesInfo){
        HashMap<String,Object> map = damagesInfoService.updateById(damagesInfo);
        return map;
    }

    @RequestMapping("/deleteAjax")
    @ResponseBody
    public HashMap<String,Object> deleteAjax(DamagesInfo damagesInfo){
        HashMap<String,Object> map = damagesInfoService.deleteById(damagesInfo);
        return map;
    }

    @RequestMapping("/select")
    @ResponseBody
    public HashMap<String,Object> select(DamagesInfo damagesInfo){
        HashMap<String,Object> map = damagesInfoService.selectAll(damagesInfo);
        //把数据传到前端
        return map;
    }

}

